package com.cn.dynamic;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class ProxyFactory {

	public static <T> T getProxy(final T obj){
		return (T)Proxy.newProxyInstance(ProxyFactory.class.getClassLoader(), obj.getClass().getInterfaces(), new InvocationHandler(){

			@Override
			public Object invoke(Object proxy, Method method, Object[] args)
					throws Throwable {
				System.out.println("打开事务");
				Object returnvalue = method.invoke(obj, args);
				System.out.println("关闭事务");
				return returnvalue;
			}
			
		});
	}
}
